package com.tbit.uqbike.object.business;

import com.tbit.common.constant.OrderLogConstant;
import com.tbit.uqbike.object.pojo.Machine;
import com.tbit.uqbike.object.pojo.OrderLog;
import com.tbit.uqbike.object.pojo.TerMsg;
import lombok.ToString;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author MyWin E-mail:335918956@qq.com
 * @version 1.0
 * @createTime 2019-12-12 20:13
 */
@ToString
public class OrderInfo {
    private Long logid;

    private Integer machineId;
    private String machineNo;
    private String userCode;
    private Date sendDt;
    private String sendRet;
    private String serNo;

    private String controlType;
    private String paramName;

    private String desc;
    private Integer businessCode;

    // 默认为-1
    private String rsp = "-1";
    private String paramRet;
    private Date rspDt;
    /**
     * 摄像头图片ftp url
     */
    private List<String> picList;

    public static TerMsg parseTerMsg(OrderInfo info) {
        TerMsg msg = new TerMsg();
        msg.setSn(info.machineNo);
        msg.setSerNO(info.serNo);
        msg.setControlType(info.controlType);
        msg.setParamName(info.paramName);//1上锁，11开锁
        //默认异步
        msg.setAsync(false);
        return msg;
    }

    public static OrderLog parseOrderLog(OrderInfo info) {
        OrderLog log = new OrderLog();

        log.setMachineid(info.machineId);
        log.setMachineno(info.machineNo);
        log.setUsercode(info.userCode);
        log.setOrderserno(info.serNo);
        log.setOptime(info.sendDt);

        log.setChanneltype(OrderLogConstant.CHANNEL_TYPE_GPRS);
        log.setOrdersource(OrderLogConstant.ORDER_SOURCE_WEB_MANAGER);

        log.setOrdercontent(info.paramName);
        log.setOrdertype(info.controlType);

        log.setBusinesstype(info.businessCode);
        /**备注*/
        log.setRemark(info.desc);

        return log;
    }

    public Long getLogid() {
        return logid;
    }

    public void setLogid(Long logid) {
        this.logid = logid;
    }

    public String getParamRet() {
        return paramRet;
    }

    public void setParamRet(String paramRet) {
        this.paramRet = paramRet;
    }

    public String getSendRet() {
        return sendRet;
    }

    public void setSendRet(String sendRet) {
        this.sendRet = sendRet;
    }

    public Date getRspDt() {
        return rspDt;
    }

    public void setRspDt(Date rspDt) {
        this.rspDt = rspDt;
    }

    public Integer getMachineId() {
        return machineId;
    }

    public void setMachineId(Integer machineId) {
        this.machineId = machineId;
    }

    public String getMachineNo() {
        return machineNo;
    }

    public void setMachineNo(String machineNo) {
        this.machineNo = machineNo;
    }

    public String getRsp() {
        return rsp;
    }

    public void setRsp(String rsp) {
        this.rsp = rsp;
    }

    public String getSerNo() {
        return serNo;
    }

    public void setSerNo(String serNo) {
        this.serNo = serNo;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public String getControlType() {
        return controlType;
    }

    public void setControlType(String controlType) {
        this.controlType = controlType;
    }

    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(Integer businessCode) {
        this.businessCode = businessCode;
    }

    public Date getSendDt() {
        return sendDt;
    }

    public void setSendDt(Date sendDt) {
        this.sendDt = sendDt;
    }

    public List<String> getPicList() {
        return picList;
    }

    public void setPicList(List<String> picList) {
        this.picList = picList;
    }

    public void initOrderInfo(Machine machine) {
        this.machineId = machine.getMachineId();
        this.machineNo = machine.getMachineNO();
        this.userCode = machine.getUserCode();
        this.serNo = UUID.randomUUID().toString();
        this.sendDt = new Date();
    }

    public void initRsp(String serNo, String rsp, String paramRet) {
        this.serNo = serNo;
        this.rsp = rsp;
        this.paramRet = paramRet;
    }
}
